package cn.ssm.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


import cn.ssm.dao.ItemMapper;
import cn.ssm.pojo.Item;



@Controller
public class ItemController {
	@Autowired
	ItemMapper itemMapper;
	// @RequestMapping锛氶噷闈㈡斁鐨勬槸璇锋眰鐨剈rl锛屽拰鐢ㄦ埛璇锋眰鐨剈rl杩涜鍖归厤
		// action鍙互鍐欎篃鍙互涓嶅啓
		@RequestMapping("/itemList")
		public ModelAndView queryItemList() {
		/*	// 鍒涘缓椤甸潰闇�鏄剧ず鐨勫晢鍝佹暟鎹�
			List<Item> list = new ArrayList<Item>();
			list.add(new Item(1, "1鍗庝负 鑽ｈ�8", 2399, new Date(), "璐ㄩ噺濂斤紒1"));
			list.add(new Item(2, "2鍗庝负 鑽ｈ�8", 2399, new Date(), "璐ㄩ噺濂斤紒2"));
			list.add(new Item(3, "3鍗庝负 鑽ｈ�8", 2399, new Date(), "璐ㄩ噺濂斤紒3"));
			list.add(new Item(4, "4鍗庝负 鑽ｈ�8", 2399, new Date(), "璐ㄩ噺濂斤紒4"));
			list.add(new Item(5, "5鍗庝负 鑽ｈ�8", 2399, new Date(), "璐ㄩ噺濂斤紒5"));
			list.add(new Item(6, "6鍗庝负 鑽ｈ�8", 2399, new Date(), "璐ㄩ噺濂斤紒6"));

			// 鍒涘缓ModelAndView锛岀敤鏉ュ瓨鏀炬暟鎹拰瑙嗗浘
			ModelAndView modelAndView = new ModelAndView();
			// 璁剧疆鏁版嵁鍒版ā鍨嬩腑
			modelAndView.addObject("itemList", list);
			// 璁剧疆瑙嗗浘jsp锛岄渶瑕佽缃鍥剧殑鐗╃悊鍦板潃
			modelAndView.setViewName("itemList");

			return modelAndView;*/
			List<Item> list = new ArrayList<Item>();
			List<Item> items = itemMapper.selectAllItem();
			for (Item item : items) {
				list.add(new Item(item.getId(), item.getName(), item.getPrice(), item.getCreatetime(), item.getDetail()));
			}
			/*list.add(new Items(1, "1锟斤拷为 锟斤拷耀8", 2399, new Date(), "锟斤拷锟斤拷锟矫ｏ拷1"));
			list.add(new Items(2, "2锟斤拷为 锟斤拷耀8", 2399, new Date(), "锟斤拷锟斤拷锟矫ｏ拷2"));
			list.add(new Items(3, "3锟斤拷为 锟斤拷耀8", 2399, new Date(), "锟斤拷锟斤拷锟矫ｏ拷3"));
			list.add(new Items(4, "4锟斤拷为 锟斤拷耀8", 2399, new Date(), "锟斤拷锟斤拷锟矫ｏ拷4"));
			list.add(new Items(5, "5锟斤拷为 锟斤拷耀8", 2399, new Date(), "锟斤拷锟斤拷锟矫ｏ拷5"));
			list.add(new Items(6, "6锟斤拷为 锟斤拷耀8", 2399, new Date(), "锟斤拷锟斤拷锟矫ｏ拷6"));*/
			ModelAndView modelAndView = new ModelAndView();
			modelAndView.addObject("itemList", list);
			modelAndView.setViewName("itemList");
			return modelAndView;
		}
		
		
}